package com.jmyd.coupon.server.config;

import com.jmyd.coupon.server.interceptors.GlobalPreInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 全局配置
 *
 * @author samphin
 * @since 2020/12/18 9:15
 */
@Configuration
@EnableWebMvc
public class GlobalConfig implements WebMvcConfigurer {
    /**
     * 全局拦截器
     *
     * @author samphin
     * @since 2021-5-24 17:49:56
     */
    @Bean
    public GlobalPreInterceptor globalPreInterceptor() {
        return new GlobalPreInterceptor();
    }

    /**
     * 添加自定义拦截器
     *
     * @param registry 拦截器注册对象
     * @author samphin
     * @since 2020-12-31 10:07:38
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //全局接口拦截
        registry.addInterceptor(globalPreInterceptor());
    }
}
